/*
 * Copyright (C) 2014 pengjianbo(pengjianbosoft@gmail.com), Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package customview.com.imageselectordemo.GalleryFinall;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.List;

import cn.finalteam.galleryfinal.model.PhotoInfo;
import customview.com.imageselectordemo.R;

/**
 * Desction:
 * Author:pengjianbo
 * Date:15/12/1 下午8:42
 */
public class ChoosePhotoListAdapter extends BaseAdapter {
    private List<PhotoInfo> mList;
    private LayoutInflater mInflater;
    private int mScreenWidth;
    private Context context;

    public ChoosePhotoListAdapter(Activity activity, List<PhotoInfo> list) {
        this.mList = list;
        this.mInflater = LayoutInflater.from(activity);
         this.context=activity;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

           ViewHolder viewHolder;
               if (convertView==null)
               {
                   viewHolder=new ViewHolder();
                   convertView=mInflater.inflate(R.layout.adapter_photo_list_item, null);
                   ImageView img = (ImageView) convertView.findViewById(R.id.iv_photo);
                   viewHolder.img=img;
                   convertView.setTag(viewHolder);
               }
                else
               {
                   viewHolder = (ViewHolder) convertView.getTag();
               }


        PhotoInfo photoInfo = mList.get(position);
     //   ImageLoader.getInstance().displayImage("file:/" + photoInfo.getPhotoPath(), ivPhoto, options);
        String filepath=photoInfo.getPhotoPath();

         Picasso.with(context).load(new File(filepath))
                .into(viewHolder.img)

        ;
        return convertView;
    }

  public  static  class ViewHolder
    {
        ImageView  img;
        public ViewHolder() {

        }

    }

   public void   setdate(List<PhotoInfo> list)
   {
       this.mList.addAll(list);
       notifyDataSetChanged();
   }
}
